#include <bits/stdc++.h>
using namespace std;
char S[110][110], T[110][110];
char temp[110][110];
int n;
// 转90度
void rotate(char a[110][110]) {
  char b[110][110];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      b[j][n + 1 - i] = a[i][j];
    }
  }
  // memcpy(a, b, sizeof(b));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      a[i][j] = b[i][j];
    }
  }
}
int check(char a[110][110], char b[110][110]) {
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[i][j] != b[i][j]) {
        ans++;
      }
    }
  }
  return ans;
}

int main() {

  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> S[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> T[i][j];
    }
  }
  int win = INT_MAX;
  for (int zhuan = 0; zhuan < 4; zhuan++) {
    int gai = check(S, T);
    win = min(win, gai + zhuan);
    rotate(S);
  }
  cout << win << endl;
  return 0;
}
